package org.springcloud.wisdom.springcloud_03_freshman.admin.service;

import org.springcloud.wisdom.springcloud_03_freshman.admin.dao.AdminFreshmanDao;
import org.springcloud.wisdom.springcloud_03_freshman.common.bean.Page;
import org.springcloud.wisdom.springcloud_03_freshman.index.login.entity.Freshman;
import org.springcloud.wisdom.springcloud_03_freshman.index.login.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminFreshmanService {
    @Autowired
    AdminFreshmanDao adminFreshmanDao;
    /**
     * 处理分页功能：
     * @param pageNum 页码数
     * @param pageSize 每页记录数
     * @param sname 姓名
     * @param dept 院系
     * @param sid 学号
     * @return
     */
    public Page<Freshman> getFreshmanPage(int pageNum, int pageSize, String sname, Integer dept, String sid){
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<Freshman> list=adminFreshmanDao.getFreshmanByCons(start,pageSize,sname,dept,sid);
        //获取总条目数
        int total=adminFreshmanDao.countFreshman(sname, dept, sid);
        //计算总页数
        int pages =(total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<Freshman> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }

    /**
     * 删除一位新生
     * @param id
     * @return
     */
    public Boolean deleteF(Integer id){
        if (id ==null || id <0 ){
            return false;
        }
        return adminFreshmanDao.deleteFresh(id)>0;
    }
    /**
     * 删除多位新生
     */
    public boolean delIds(List<Integer> ids) {
        if (null==ids ||ids.size()==0){
            return false;
        }
        return adminFreshmanDao.delbyIds(ids)>0;
    }
}
